package org.bulu.project.web.controller;


import org.bulu.project.common.result.Result;
import org.bulu.project.system.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/like")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @PostMapping("/add")
    public Result<Long> addLike(@RequestParam Integer uid, @RequestParam Integer vid) {
        Long result = likeService.insertLike(uid, vid);
        if(result > 0){
            return Result.success(result);
        }
        return Result.failed("点赞失败");
    }

    @PostMapping("/delete")
    public Result<Long> deleteLike(@RequestParam Integer uid, @RequestParam Integer vid) {
        Long result = likeService.deleteLike(uid, vid);
        if(result > 0){
            return Result.success(result);
        }
        return Result.failed("取消点赞失败");
    }

    @GetMapping("/count")
    public Result<Long> countLikes(@RequestParam Integer vid) {
        Long result= likeService.countLikes(vid);
        if(result == null){
            return Result.failed("获取点赞数失败");
        }
        return Result.success(result);
    }
}
